import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.io.IOException;
public class intersection {
    //performs in O(n^2) time
    public static void main (String[] args) throws IOException {
        if (args.length<1) throw new RuntimeException ("not enough arguments");
        if (args.length>1) throw new RuntimeException ("too many arguments");
        BufferedReader reader = new BufferedReader (new FileReader (new File (args[0])));
        String line;
        
        while ((line = reader.readLine()) !=null){
            String output = "";
            String[] lists = line.split(";");
            String[] list1 = lists[0].split(",");
            String[] list2 = lists[1].split(",");
            for (int i = 0; i<list1.length;i++){
                for (int j = 0; j<list2.length;j++) {
                    if (list1[i].equals(list2[j])) output = output.concat(list1[i]+",");
                }
            }
             if (output !=""){
                 if (output.charAt(output.length()-1) == ',') output = output.substring(0,output.length()-1);
                 System.out.println(output);
             }
        }
            
    }
}